#ifndef TWISTINGWIDGET_H
#define TWISTINGWIDGET_H

#include <QtOpenGL/QtOpenGL>
#include "cg/cg.h"
#include "cg/cgGL.h"

class TwistingWidget : public QGLWidget
{
	Q_OBJECT

public:
	TwistingWidget(QWidget *parent =0);
	~TwistingWidget();
protected:
	void initializeGL();
	void resizeGL(int w, int h );
	void paintGL();

	void keyPressEvent(QKeyEvent *ev);

private:
	void initCG();
	void makeModel();
	void checkForCgError(const char *situation);
	void display();

	void triangleDivide(int depth , const float a[2] , const float b[2] , const float c[2] , const float ca[3],const float cb[3] , const float cc[3]);
	void drawSubDividedTriangle(int subdivisions);

private slots:
	void animate();
private:
	CGcontext fCgContext;
	CGprogram fCgVertexProgram;
	CGprogram fCgFragmentProgram;
	CGprofile fCgVertexProfile;
	CGprofile fCgFragmentProfile;
	CGparameter fCgVertexParam_twisting;
	
	GLfloat fTwistingParameterValue;
	GLfloat fTwistingDirection;
	QTimer fTimer;
	GLboolean fWireframed;
	GLboolean fAnimated;
};

#endif // TWISTINGWIDGET_H
